class smx_nginx::main {
  require smx_os

  Exec {
    path      => [
      '/usr/bin',
      '/bin',
    ],
    logoutput => true,
    timeout   => 0,
  }
  package { 'nginx':
    ensure  => installed,
    require => File["/etc/yum.repos.d/nginx.repo"],
    notify  => Service['nginx'],
  }

  file { "/etc/yum.repos.d/nginx.repo":
    ensure => file,
    group  => root, owner  => root,
    mode   => 644,
    source => 'puppet:///modules/smx_nginx/nginx.repo',
  }

  file { "/etc/nginx/nginx.conf":
    ensure  => file,
    group   => root, owner  => root,
    mode    => 644,
    require => Package['nginx'],
    notify  => Service['nginx'],
    content => template('smx_nginx/nginx.conf.erb'),
  }

  file { '/vagrant/vagrant/api.json':
    ensure => file,
    mode   => 644,
    #      owner => root, group => root,
    source =>  "puppet:///modules/smx_nginx/api.json",
  }

  file { '/etc/nginx/vhost':
    ensure  => directory,
    group   => root, owner  => root,
    mode    => 644,
    require => Package['nginx'],
    notify  => Service['nginx'],
    source  => 'puppet:///modules/smx_nginx/vhost',
    recurse => true,
  }


  file { '/etc/nginx/conf':
    ensure  => directory,
    group   => root, owner  => root,
    mode    => 644,
    require => Package['nginx'],
    notify  => Service['nginx'],
    source  => 'puppet:///modules/smx_nginx/conf',
    recurse => true,
  }

  file { '/etc/nginx/keys':
    ensure  => directory,
    group   => root, owner  => root,
    mode    => 644,
    require => Package['nginx'],
    notify  => Service['nginx'],
    source  => 'puppet:///modules/smx_nginx/keys',
    recurse => true,
  }
  service { 'httpd':
    ensure => stopped,
    enable => false,
  }
  service { 'nginx':
    ensure  => running,
    enable  => true,
    require => Service['httpd'],
  }

  exec { '_setup_nginx.sh':
    cwd       => '/vagrant/vagrant',
    command   => '/bin/bash _setup_nginx.sh',
    require   => File['/etc/nginx/vhost','/vagrant/vagrant/api.json'],
  }

  # nginx --http-fastcgi-temp-path definition path
  file { '/var/cache/nginx':
    ensure  => directory,
    group   => vagrant, owner  => vagrant,
    recurse => true,
    require => Service['nginx'],
  }
  #    file { ['/vagrant/webapp/connectedpdfapp/web/dll-config','/vagrant/webapp/connectedpdfapp/web/dll-config/1.0']:
  #    ensure => directory,
  #    mode => 755,
  #  }

  #    file { '/vagrant/webapp/connectedpdfapp/web/dll-config/1.0/cpdfApi.json':
  #    ensure => file,
  #    mode => 755, owner => vagrant, group => vagrant,
  #    source =>  "puppet:///modules/smx_nginx/cpdfApi.json",
  #    require => File['/vagrant/webapp/connectedpdfapp/web/dll-config/1.0'],
  #  }

  file { '/var/lib/foxit_ucx':
    ensure => 'link',
    target => '/vagrant/webapp',
  }


}
